package com.project8.main;

import java.util.ArrayList;
import com.project8.book.Chapter;
import com.project8.book.Figure;
import android.widget.AdapterView;
import android.widget.GridView;
import android.view.View;
import android.widget.AdapterView.OnItemClickListener;


public class TableOfFigs
{
	GridView gridview;
	
	ArrayList<ToFAdapter> allChapterGrids;
		
	public TableOfFigs(final TableOfFigure main)
	{
		allChapterGrids = new ArrayList<ToFAdapter>();
		
		for(int c = 0; c < main.book.numChapters(); c++)
		{			
			ArrayList<Figure> listOfThumbnails = new ArrayList<Figure>();
			Chapter thisChapter = main.book.getChapters().get(c);
						
			for(int f = 0; f < thisChapter.getAllFigures().size(); f++)
				listOfThumbnails.add(thisChapter.getAllFigures().get(f));
									
			ToFAdapter tofGrid = new ToFAdapter(main, listOfThumbnails, main, thisChapter);
			
			allChapterGrids.add(tofGrid);
		}
							    	    	   			
		gridview = (GridView) main.findViewById(R.id.tofGridView);
		gridview.setAdapter(allChapterGrids.get(0));
		
		gridview.setOnItemClickListener(new OnItemClickListener() 
		{
			public void onItemClick(AdapterView<?> parent, View v, int position, long id){ }
		});
	}
	
	public void displayNewChapter(TableOfFigure main, Chapter lastChapterOnDisplay)
	{		
		gridview = (GridView) main.findViewById(R.id.tofGridView);
		gridview.setAdapter(allChapterGrids.get((int)lastChapterOnDisplay.getId()));

		gridview.setOnItemClickListener(new OnItemClickListener() 
		{
			public void onItemClick(AdapterView<?> parent, View v, int position, long id){ }
		});
	}
}
